package yunhe.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.Reader;

public class SqlSessionFactoryUtil {
	
	private static SqlSessionFactory factory;
	
	private SqlSessionFactoryUtil(){
	}
	static{
		try (Reader r=Resources.getResourceAsReader("mybatisConfig.xml")){
			
			factory=new SqlSessionFactoryBuilder().build(r);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static SqlSession getSqlSession(){
		return factory.openSession();
	}
}
